package com.example.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;

//当注释掉该注解时，该过滤器就不生效
//@WebFilter(urlPatterns = "/*")
public class demoFilter implements Filter {
    //初始化方法，启动web服务器，创建Filter时调用，只调用一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);

    }

    //拦截到请求时，调用该方法，可调用多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("拦截到了请求");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);
    }

    //销毁方法，服务器关闭时调用一次
    @Override
    public void destroy() {

        System.out.println("销毁方法执行了");
    }
}
